<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
    <legend>添加汽车信息</legend>
</fieldset>

<form class="layui-form" action="">
    <div class="layui-form-item">
        <label class="layui-form-label">汽车车牌号</label>
        <div class="layui-input-block">
            <input type="text" name="carnumber" lay-verify="username" autocomplete="off" placeholder="请输入汽车车牌号" class="layui-input">
        </div>
        <br>
        <label class="layui-form-label">汽车类型</label>
        <div class="layui-input-block">
            <select name="cartype" lay-filter="aihao">
                <option value="微型车">微型车</option>
                <option value="中型车">中型车</option>
                <option value="大中型">大中型</option>
                <option value="豪华型">豪华型</option>
                <option value="小型车">小型车</option>
            </select>
        </div>
        <br>
        <label class="layui-form-label">汽车价值</label>
        <div class="layui-input-block">
            <input type="text" name="price" lay-verify="required" autocomplete="off" placeholder="请输入汽车价值" class="layui-input">
        </div>
        <br>
        <label class="layui-form-label">
            汽车租金</label>
        <div class="layui-input-block">
            <input type="text" name="rentprice" lay-verify="required" autocomplete="off" placeholder="请输入汽车租金" class="layui-input">
        </div>
        <br>
        <label class="layui-form-label">租车押金</label>
        <div class="layui-input-block">
            <input type="text" name="deposit" lay-verify="required" autocomplete="off" placeholder="请输入租车押金" class="layui-input">
        </div>
        <br>
        <label class="layui-form-label">汽车状态</label>
        <div class="layui-input-block">
            <select name="isrenting" lay-filter="aihao">
                <option value="租 出">租 出"</option>
                <option value="可 租">可 租</option>
            </select>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit="" lay-filter="demo1">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>
<script>
    layui.use(["jquery","form"],function () {
        var $=layui.jquery,form=layui.form;

        form.on('submit(demo1)', function(data){//提交按钮
            $.ajax({
                url:"/Cars/add",
                data:data.field,
                dataType:"json",
                type:"post",
                success:function (msg) {
                    if (msg.code==0){
                        tableIns.reload({
                            page:{
                                curr:1
                            }
                        });
                        layer.msg(msg.msg);//提示后台传过来的信息
                        layer.close(openIndex);//关闭当前页面
                    }else {
                        layer.msg(msg.msg);//提示后台过来的信息
                    }
                }
            });
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });
        //显示下拉框
        layui.use('form', function(){
            var form = layui.form;
            form.render();

        });
        form.verify({
            username: function (value, item) { //value：表单的值、item：表单的DOM对象
                if (!new RegExp("^[a-zA-Z0-9_\u4e00-\u9fa5\\s·]+$").test(value)) {
                    return '用户名不能有特殊字符';
                }
                if (/(^\_)|(\__)|(\_+$)/.test(value)) {
                    return '用户名首尾不能出现下划线\'_\'';
                }
                if (/^\d+\d+\d$/.test(value)) {
                    return '用户名不能全为数字';
                }
                if (/^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领A-Z]{1}[A-Z]{1}[A-Z0-9]{4}[A-Z0-9挂学警港澳]{1}$/.test(value)) {
                    return '车牌号必须严格要求制度';
                }


            }
        });
    });
</script>